package com.szbmyoubao.app.ui.splash

import android.annotation.SuppressLint
import android.os.Bundle
import com.szbmyoubao.app.App
import com.szbmyoubao.app.storage.AppStorage
import com.szbmyoubao.app.ui.MainActivity
import com.szbmyoubao.app.ui.login.LoginActivity
import com.szbmyoubao.app.view.dialog.AgreementDialog
import com.ellecity06.common.base.BaseMvvmActivity
import com.ellecity06.common.base.BaseViewModel
import com.ellecity06.common.ktx.launchActivity
import com.ellecity06.cwhiskymall.databinding.ActivitySplashBinding

/**
 * @author ellecity06
 * @time 2023/4/15 10:22
 * @des
 */

@SuppressLint("CustomSplashScreen")
open class SplashActivity : BaseMvvmActivity<ActivitySplashBinding, BaseViewModel>() {
    override val userBaseTitle: Boolean
        get() = false

    override fun inflateBinding(): ActivitySplashBinding =
        ActivitySplashBinding.inflate(layoutInflater)

    override fun initialize(savedInstanceState: Bundle?) {
        if (AppStorage.Companion.agreement) {
            toMain()
        } else {
            AgreementDialog(this, cancel = {
                finish()
            }, confirm = {
                AppStorage.Companion.agreement = true
                App.Companion.appContext.initSdk()
                toMain()
            }).show()
        }
    }

    private fun toMain() {
        if (AppStorage.Companion.token.isNullOrEmpty()) {
            launchActivity<MainActivity>()
        } else {
            launchActivity<MainActivity>()
        }
        finish()
    }
}